package com.net.tcpTest;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class TcpServer {
    public static void main(String[] args) throws IOException {
        ServerSocket server = new ServerSocket(8189);
        Socket accept = server.accept();
        System.out.println("客户端连接成功");
        InputStream inputStream = accept.getInputStream();
        Scanner in = new Scanner(inputStream, String.valueOf(StandardCharsets.UTF_8));
        while(in.hasNextLine()) {
            //一直阻塞 read读取
            String msg = in.nextLine();
            System.out.println(msg);
            if (msg.equals("bye")) {
                break;

            }
        }
        accept.close();

    }
}
